/*
 * ApplicationMediator.java
 * Copyright (C) Jul 4, 2012 Bora SAYINER
 *
 * This file is part of Design Patterns.
 *
 * Design Patterns is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * Design Patterns is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Design Patterns. If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package net.samples.mediator;

import java.util.ArrayList;

/**
 * 
 * @author Bora SAYINER
 * @since Jul 4, 2012
 * @version 1.0.0
 */
public class ApplicationMediator implements Mediator {

	private final ArrayList<Colleague> colleagues = new ArrayList<>();

	public void addColleague(Colleague colleague) {
		this.colleagues.add(colleague);
	}

	@Override
	public void send(String message, Colleague sender) {
		for (Colleague colleague : colleagues) {
			if (colleague != sender) {
				colleague.receiveMessage(message, sender);
			}
		}
	}

	@Override
	public void send(String message, Colleague sender, Colleague receiver) {
		receiver.receiveMessage(message, sender);
	}

	@Override
	public void send(String message, Colleague sender, Colleague... receiver) {
		for (Colleague colleague : receiver) {
			colleague.receiveMessage(message, sender);
		}
	}

}
